package com.taotao.manage.service.impl;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.taotao.manage.mapper.ItemDescMapper;
import com.taotao.manage.mapper.ItemMapper;
import com.taotao.manage.pojo.Item;
import com.taotao.manage.pojo.ItemDesc;
import com.taotao.manage.service.ItemService;

@Service
public class ItemServiceImpl extends BaseServiceImpl<Item> implements ItemService {

	@Autowired
	private ItemMapper itemMapper;

	@Autowired
	private ItemDescMapper itemDescMapper;

	/*
	 * 新增商品(non-Javadoc)
	 * @see com.taotao.manage.service.ItemService#saveItem(com.taotao.manage.pojo.Item, java.lang.String)
	 */
	@Override
	public Long saveItem(Item item, String desc) {

		// 保存商品基本信息
		saveSelective(item);

		// 保存商品描述信息
		ItemDesc itemDesc = new ItemDesc();
		itemDesc.setItemId(item.getId());
		itemDesc.setCreated(new Date());
		itemDesc.setItemDesc(desc);
		itemDesc.setUpdated(itemDesc.getCreated());
		itemDescMapper.insertSelective(itemDesc);
		return item.getId();

	}

	/*
	 * 修改商品(non-Javadoc)
	 * @see com.taotao.manage.service.ItemService#updateItem(com.taotao.manage.pojo.Item, java.lang.String)
	 */
	@Override
	public void updateItem(Item item, String desc) {
		//更新商品基本信息
		updateSelective(item);
		
		//更新商品描述信息
		ItemDesc itemDesc=new ItemDesc();
		itemDesc.setItemId(item.getId());
		itemDesc.setItemDesc(desc);
		itemDesc.setUpdated(new Date());
		itemDescMapper.updateByPrimaryKeySelective(itemDesc);
	}

}
